﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using BBInterfaceNET.CommonServices;

namespace BBInterfaceNET.Toolbox.ViewModels
{
    public class ToolboxViewModel
    {
        public ToolboxViewModel(IToolboxService toolboxService)
        {
            this.toolboxService = toolboxService;
        }

        public List<ToolboxItem> Items
        {
            get
            {
                if (items == null)
                {
                    items = toolboxService.GetItems().OrderBy(p => p.Description).ToList();
                    CollectionView cv = CollectionViewSource.GetDefaultView(items) as CollectionView;
                    if (cv != null)
                        cv.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
                }
                return items;
            }
        }

        private IToolboxService toolboxService;
        private List<ToolboxItem> items;
    }
}
